import java.util.*;

/**
 * @author zyj
 * @date 2022年05月20日 14:51
 */
public class MapDemo {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<>();
        //添加内容
        map.put(1,"张三");
        map.put(2,"兰蒂斯");
        map.put(3,"利蒂斯");
        map.put(4,"亚特拉大");
        map.put(5,"笑破伦");
        //判断某一个key是否存在
        System.out.println(map.containsKey(1));
        //判断某一个value是否存在
        System.out.println(map.containsValue("笑破伦"));

        System.out.println(map.get(5));

        //map的遍历
       map.forEach((k,v) ->{
           System.out.println(k + ":" + v);
       });

        System.out.println("*********************************");
       //keySet()
        Set<Integer> set = map.keySet();
        Iterator<Integer> iterator = set.iterator();
        while (iterator.hasNext()){
            int key = iterator.next();
            System.out.println(key + ":" + map.get(key));
        }
        System.out.println("*********************************");

        Collection<String> collection = map.values();

        for (String s:collection) {
            System.out.println(s);
        }
        System.out.println("*********************************");

        Set<Map.Entry<Integer,String>> mapSet = map.entrySet();
       Iterator<Map.Entry<Integer,String>> iterator1 =  mapSet.iterator();
       while (iterator1.hasNext()){
          Map.Entry<Integer,String> entry =  iterator1.next();
           System.out.println(entry.getKey() + ":" + entry.getValue());
       }
    }
}
